/*
 * Copyright (c) 2024. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package com.neusoft.npi.admin.controller;

import com.neusoft.npi.admin.service.RoleService;
import com.neusoft.npi.common.entity.CommonResult;
import com.neusoft.npi.common.entity.Role;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("role")
@Slf4j
@CrossOrigin("*")
public class RoleController {

    @Autowired private RoleService roleService;

    //    /m/auth4role/byid/' + this.role.roleid
    @PutMapping("/m/auth4role/byid/{roleid}")
    public CommonResult auth4Role(
            @PathVariable("roleid") Integer roleid, @RequestBody List<Integer> sysids) {
        return roleService.auth4Role(roleid, sysids);
    }

    @PutMapping("/m/role/byid")
    public CommonResult updateRole(@RequestBody Role role) {
        return roleService.updateRole(role);
    }

    @GetMapping("q/findall/sysnodes/list/{empno}")
    public CommonResult findAllSysNodesList(@PathVariable("empno") Integer empno) {
        return roleService.findAllSysNodesList(empno);
    }

    @GetMapping("q/findall/sysnodes/tree")
    public CommonResult findAllSysNodesTree() {
        return roleService.findAllSysNodesTree();
    }

    @GetMapping("q/findall/role")
    public CommonResult findAllRole() {
        return roleService.findAllRole();
    }

    @GetMapping("q/findall/sysnodeid/byroleid/{roleid}")
    public CommonResult findAllSysnodeIdsByRoleId(@PathVariable("roleid") Integer roleid) {
        return roleService.findAllSysnodeIdsByRoleId(roleid);
    }
}
